package com.hit.aircraftwar.httputil;

import android.app.Application;

import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.cookie.CookieJarImpl;
import com.zhy.http.okhttp.cookie.store.PersistentCookieStore;
import com.zhy.http.okhttp.log.LoggerInterceptor;

import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;


public class HttpUtils {
    public static HttpUtils httpUtils;
    public HttpUtils() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        //获取当前的Appilication，进行网络请求的初始化设置
        Application mApplication = (Application) Class.forName("android.app.ActivityThread").getMethod("currentApplication").invoke(null,(Object[])null);
        CookieJarImpl cookieJar = new CookieJarImpl(new PersistentCookieStore(mApplication.getApplicationContext()));
        OkHttpClient okHttpClient = new OkHttpClient.Builder()
                .cookieJar(cookieJar)
                .addInterceptor(new LoggerInterceptor("TAG"))
                .connectTimeout(10000L, TimeUnit.MILLISECONDS)
                .readTimeout(10000L, TimeUnit.MILLISECONDS)
                //其他配置
                .build();
        OkHttpUtils.initClient(okHttpClient);
    }

    public boolean login(){
        return false;
    }
}
